package day05;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author Huangjin
 * @version 1.0
 * describe:
 * @date 2023/2/16 18:01
 */
public class WorkTwo {
    public static void main(String[] args) {
        addition();
        multiTable();
        arrayPractice();
        maxOfArray();
        arraySort();
    }
    public static void addition(){
        Scanner sc = new Scanner(System.in);
        int score = 0;
        for (int i = 0; i <= 10; i++) {
            int a = (int)(Math.random()*100);
            int b = (int)(Math.random()*100);
            int c = a*b;
            System.out.println("("+i+")"+a+" + "+b+"= ?");
            System.out.println("请开始作答：");
            int input = sc.nextInt();
            if (input==c){
                System.out.println("恭喜你，答对了！");
                score+=10;
            }else {
                System.out.println("很遗憾，答错了！");
            }
        }
        System.out.println("你答题的总分："+score+"分");
    }
    public static void multiTable(){
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(j+" * "+i+" = "+j*i+"\t");
            }
            System.out.println();
        }
    }
    public static void arrayPractice(){
        int[] arr1 = new int[3];
        int[] arr2 = {2,5,8};
        int[] arr3 = new int[]{2,5,8};
        int[] arr4;
        //arr4 = {2,5,8};
        arr4 = new int[]{2,5,8};


        int[] arr = new int[3];
        System.out.println(arr.length);
        arr[0] = 100;
        arr[1] = 200;
        arr[2] = 300;
        //arr[3] = 400;
        System.out.println(arr[arr.length-1]);

        int[] arr5 = new int[10];
        for(int i=0;i<arr5.length;i++){
            arr5[i] = (int)(Math.random()*100);
            System.out.println(arr5[i]);
        }
    }
    public static void maxOfArray(){
        int[] arr = new int[10];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int)(Math.random()*100);
            System.out.print(arr[i]+"\t");
        }
        System.out.println();
        int max = 0;
        for (int i = 0; i < arr.length; i++) {
            if (max<arr[i]){
                max = arr[i];
            }
        }
        System.out.println("最大值为："+max);
    }
    public static void arraySort(){
        int[] arr = new int[10];
        System.out.println("排序前：");
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int)(Math.random()*100);
            System.out.print(arr[i]+"\t");
        }
        System.out.println();
        Arrays.sort(arr);
        System.out.println("排序后：");
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+"\t");
        }

    }
}
